
/*-----------------------------------------------------------------------------\
|                            The Pomodoro technique                            |
|                                                                              |
| Developer: Felipe Simões Lage Gomes Duarte                                   |
|                                                                              |
| Main Project: The Pomodoro technique                                         |
| Date: 28 / maio / 2011                                                       |
| Code: Configuration.java                                                     |
| IDE: NetBeans IDE 7.0 (Build 201104080000)                                   |
| Java: 1.6.0_24; Java HotSpot(TM) Client VM 19.1-b02                          |
|                                                                              |
\-----------------------------------------------------------------------------*/

package interfaces;

/**
 *
 * @author felipelageduarte
 */
public class Configuration extends javax.swing.JFrame {

   private static Configuration SINGLETON = null;
   private int wt = 25;
   private int sit = 5;
   private int lit = 20;
   private int p = 4;

   /** Creates new form Configuracao */
   private Configuration() {
      initComponents();
      FrameInTheMiddle.centerFrameOnScreen(this);
      workingTime.setValue(wt);
      shorterIntervalTime.setValue(sit);
      logestIntervalTime.setValue(lit);
   }

   public static Configuration getInstance() {
      if (SINGLETON == null) {
         SINGLETON = new Configuration();
      }
      return SINGLETON;
   }

   public int getLit() {
      return lit;
   }

   public void setLit(int lit) {
      this.lit = lit;
   }

   public int getSit() {
      return sit;
   }

   public void setSit(int sit) {
      this.sit = sit;
   }

   public int getWt() {
      return wt;
   }

   public void setWt(int wt) {
      this.wt = wt;
   }

   public int getP() {
      return p;
   }

   public void setP(int p) {
      this.p = p;
   }
   
   

   /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      jPanel2 = new javax.swing.JPanel();
      okButton = new javax.swing.JButton();
      cancelButton = new javax.swing.JButton();
      applyButton = new javax.swing.JButton();
      jPanel1 = new javax.swing.JPanel();
      jSeparator1 = new javax.swing.JSeparator();
      jLabel5 = new javax.swing.JLabel();
      jLabel6 = new javax.swing.JLabel();
      jLabel1 = new javax.swing.JLabel();
      shorterIntervalTime = new javax.swing.JSpinner();
      jLabel3 = new javax.swing.JLabel();
      workingTime = new javax.swing.JSpinner();
      jLabel2 = new javax.swing.JLabel();
      logestIntervalTime = new javax.swing.JSpinner();
      jLabel4 = new javax.swing.JLabel();
      defaultButton = new javax.swing.JButton();
      jPanel3 = new javax.swing.JPanel();
      jLabel7 = new javax.swing.JLabel();
      numberPomodoro = new javax.swing.JSpinner();
      jLabel8 = new javax.swing.JLabel();

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      setAlwaysOnTop(true);
      setResizable(false);

      jPanel2.setBorder(new javax.swing.border.MatteBorder(null));

      okButton.setText("Ok");
      okButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            okButtonActionPerformed(evt);
         }
      });

      cancelButton.setText("Cancel");
      cancelButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cancelButtonActionPerformed(evt);
         }
      });

      applyButton.setText("Apply");
      applyButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            applyButtonActionPerformed(evt);
         }
      });

      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Time"));

      jLabel5.setText("min.");

      jLabel6.setText("min.");

      jLabel1.setText("min.");

      shorterIntervalTime.setModel(new javax.swing.SpinnerNumberModel(5, 1, 720, 1));

      jLabel3.setText("Shorter Interval Time:");

      workingTime.setModel(new javax.swing.SpinnerNumberModel(25, 1, 720, 1));

      jLabel2.setText("Working Time");

      logestIntervalTime.setModel(new javax.swing.SpinnerNumberModel(20, 1, 720, 1));

      jLabel4.setText("Longest Interval Time:");

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
         jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
               .addGroup(jPanel1Layout.createSequentialGroup()
                  .addComponent(jLabel2)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(workingTime, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(jLabel1))
               .addGroup(jPanel1Layout.createSequentialGroup()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jLabel4)
                     .addComponent(jLabel3))
                  .addGap(18, 18, 18)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(shorterIntervalTime, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                     .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(logestIntervalTime, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)))))
            .addContainerGap())
      );
      jPanel1Layout.setVerticalGroup(
         jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(jLabel2)
               .addComponent(workingTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(jLabel1))
            .addGap(18, 18, 18)
            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(jLabel3)
               .addComponent(shorterIntervalTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(jLabel5))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(jLabel4)
               .addComponent(logestIntervalTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(jLabel6))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      defaultButton.setText("Default");
      defaultButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            defaultButtonActionPerformed(evt);
         }
      });

      jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Pomodoro"));

      jLabel7.setText("Number of Pomodoro");

      numberPomodoro.setModel(new javax.swing.SpinnerNumberModel(4, 1, 10, 1));

      jLabel8.setText("un.");

      javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
      jPanel3.setLayout(jPanel3Layout);
      jPanel3Layout.setHorizontalGroup(
         jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(18, 18, 18)
            .addComponent(numberPomodoro, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
            .addGap(111, 111, 111))
      );
      jPanel3Layout.setVerticalGroup(
         jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(jLabel7)
               .addComponent(numberPomodoro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(jLabel8))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
      jPanel2.setLayout(jPanel2Layout);
      jPanel2Layout.setHorizontalGroup(
         jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel2Layout.createSequentialGroup()
                  .addGap(12, 12, 12)
                  .addComponent(defaultButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(applyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
               .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
      );
      jPanel2Layout.setVerticalGroup(
         jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(okButton)
               .addComponent(cancelButton)
               .addComponent(applyButton)
               .addComponent(defaultButton))
            .addContainerGap())
      );

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents

   private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
      this.setVisible(false);
   }//GEN-LAST:event_cancelButtonActionPerformed

   //same as applyButton Action + hide the windows
   private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
      wt = (Integer)workingTime.getValue();
      sit = (Integer)shorterIntervalTime.getValue();
      lit = (Integer)logestIntervalTime.getValue();
      p = (Integer)numberPomodoro.getValue();
      this.setVisible(false);
   }//GEN-LAST:event_okButtonActionPerformed

   private void defaultButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultButtonActionPerformed
      //assigns default values
      wt = 25; sit = 5; lit = 20; p = 4;
      
      //apply at JSpinner
      workingTime.setValue(wt);
      shorterIntervalTime.setValue(sit);
      logestIntervalTime.setValue(lit);
      numberPomodoro.setValue(p);
      
      Log.info("Default configuration successfully loaded");
   }//GEN-LAST:event_defaultButtonActionPerformed
   
   //override setVisible to set correct values at interface. Once they are
   //singleton, if user press cancel and reopen it, the last value will be
   //displayed at JSpinner
   @Override
   public void setVisible(boolean status){
      super.setVisible(status);
      workingTime.setValue(wt);
      shorterIntervalTime.setValue(sit);
      logestIntervalTime.setValue(lit);
      numberPomodoro.setValue(p);
   }
   
   //apply new values
   private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
      wt = (Integer)workingTime.getValue();
      sit = (Integer)shorterIntervalTime.getValue();
      lit = (Integer)logestIntervalTime.getValue();
      p = (Integer)numberPomodoro.getValue();
   }//GEN-LAST:event_applyButtonActionPerformed

   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JButton applyButton;
   private javax.swing.JButton cancelButton;
   private javax.swing.JButton defaultButton;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JLabel jLabel2;
   private javax.swing.JLabel jLabel3;
   private javax.swing.JLabel jLabel4;
   private javax.swing.JLabel jLabel5;
   private javax.swing.JLabel jLabel6;
   private javax.swing.JLabel jLabel7;
   private javax.swing.JLabel jLabel8;
   private javax.swing.JPanel jPanel1;
   private javax.swing.JPanel jPanel2;
   private javax.swing.JPanel jPanel3;
   private javax.swing.JSeparator jSeparator1;
   private javax.swing.JSpinner logestIntervalTime;
   private javax.swing.JSpinner numberPomodoro;
   private javax.swing.JButton okButton;
   private javax.swing.JSpinner shorterIntervalTime;
   private javax.swing.JSpinner workingTime;
   // End of variables declaration//GEN-END:variables
}
